import resources.Constants;

import registnet.records.summary.honorary.source.HonorRollSource;
import registnet.records.summary.honorary.HonorRoll;
import registnet.records.summary.honorary.source.CollegeScholarsSource;
import registnet.records.summary.honorary.CollegeScholars;
import registnet.records.summary.honorary.source.UniversityScholarsSource;
import registnet.records.summary.honorary.UniversityScholars;
import registnet.records.source.CollegeSource;
import registnet.records.College;
import registnet.records.Student;
		
/* [start] 	initializes gui variables */
String _honorary_students = bundle.getProperty("registnet.module.summaries.honorary_students");

String _academic_year = bundle.getProperty("registnet.module.summaries.macro.honorary_students.search.academic_year");
String _semester = bundle.getProperty("registnet.module.summaries.macro.honorary_students.search.semester");
String _type = bundle.getProperty("registnet.module.summaries.macro.honorary_students.search.course");

String _student_number = bundle.getProperty("registnet.module.summaries.macro.honorary_students.form.student_number");
String _full_name = bundle.getProperty("registnet.module.summaries.macro.honorary_students.form.full_name");
String _sex = bundle.getProperty("registnet.module.summaries.macro.honorary_students.form.sex");
String _college = bundle.getProperty("registnet.module.summaries.macro.honorary_students.form.college");
String _degree_course = bundle.getProperty("registnet.module.summaries.macro.honorary_students.form.degree_course");
String _gwa = bundle.getProperty("registnet.module.summaries.macro.honorary_students.form.gwa");

String _university_scholar = Constants.UNIVERSITY_SCHOLAR;
String _college_scholar = Constants.COLLEGE_SCHOLAR;
String _honor_roll = Constants.HONOR_ROLL;

/* [end] */
		

private class HonoraryStudentsRenderer implements RowRenderer  {
	public void render(Row row, java.lang.Object data) {
		if (data[0] != null){
			new Label(data[0]).setParent(row);
			new Label(data[1]).setParent(row);
			new Label(data[2]).setParent(row);
			new Label(data[3]).setParent(row);
			new Label(data[4]).setParent(row);
			new Label(data[5]).setParent(row);
			new Label(data[6]).setParent(row);
		}
		else{
			row.setVisible(false);
		}
	}
}

void retrieveHonorRollList(){
	Integer semesterValue = Constants.MAP_SEMESTER_KEY.get(semester.getSelectedItem().getLabel());
	Integer yearValue;
	if (semesterValue == Constants.MAP_SEMESTER_KEY.get(Constants.SUMMER))
		yearValue = Integer.parseInt(year2.value);
	else
		yearValue = Integer.parseInt(year1.value);
		
	HashMap honorRoll;
	if (_user_type.equals(Constants.REGISTRAR))
		 honorRoll = new HonorRollSource(semesterValue, yearValue).getHonoraryStudents().getHonorList();
	else if (_user_type.equals(Constants.COLLEGE)){
		College college = new CollegeSource(_office).getCollege();
		honorRoll = new HonorRollSource(college, semesterValue, yearValue).getHonoraryStudents().getHonorList();
	}
	Iterator iter = honorRoll.keySet().iterator();
	String[][] listModel = new String[honorRoll.size()][7];
	int i=0;
	while(iter.hasNext()){
		Student student = iter.next();
		listModel[i][0] = (i + 1) + "";
		listModel[i][1] = student.getStudentNumber();
		listModel[i][2] = student.getLastName() + " " + student.getFirstName() + " " + student.getMiddleName();
		listModel[i][3] = student.getSex();
		listModel[i][4] = student.getCurriculum().getDegreeProgram().getCollege().getCollegeCode();
		listModel[i][5] = student.getCurriculum().getDegreeProgram().getDegreeCode();
		listModel[i][6] = honorRoll.get(student).toString();
		i++;
	}
	ListModel strset = new SimpleListModel(listModel);
	contents_win.getFellow("honorary_g").setModel(strset);
	contents_win.getFellow("honorary_g").setRowRenderer(new HonoraryStudentsRenderer());
}

void retrieveCollegeScholarList(){
	Integer semesterValue = Constants.MAP_SEMESTER_KEY.get(semester.getSelectedItem().getLabel());
	Integer yearValue;
	if (semesterValue == Constants.MAP_SEMESTER_KEY.get(Constants.SUMMER))
		yearValue = Integer.parseInt(year2.value);
	else
		yearValue = Integer.parseInt(year1.value);
	
	HashMap collegeScholar;
	if (_user_type.equals(Constants.REGISTRAR))
		collegeScholar = new CollegeScholarsSource(semesterValue, yearValue).getHonoraryStudents().getHonorList();
	else if (_user_type.equals(Constants.COLLEGE)){
		College college = new CollegeSource(_office).getCollege();
		collegeScholar = new CollegeScholarsSource(college, semesterValue, yearValue).getHonoraryStudents().getHonorList();
	}
	Iterator iter = collegeScholar.keySet().iterator();
	String[][] listModel = new String[collegeScholar.size()][7];
	int i=0;
	while(iter.hasNext()){
		Student student = iter.next();
		listModel[i][0] = (i + 1) + "";
		listModel[i][1] = student.getStudentNumber();
		listModel[i][2] = student.getLastName() + " " + student.getFirstName() + " " + student.getMiddleName();
		listModel[i][3] = student.getSex();
		listModel[i][4] = student.getCurriculum().getDegreeProgram().getCollege().getCollegeCode();
		listModel[i][5] = student.getCurriculum().getDegreeProgram().getDegreeCode();
		listModel[i][6] = collegeScholar.get(student).toString();
		i++;
	}
	ListModel strset = new SimpleListModel(listModel);
	contents_win.getFellow("honorary_g").setModel(strset);
	contents_win.getFellow("honorary_g").setRowRenderer(new HonoraryStudentsRenderer());
}


void retrieveUniversityScholarList(){
	Integer semesterValue = Constants.MAP_SEMESTER_KEY.get(semester.getSelectedItem().getLabel());
	Integer yearValue;
	if (semesterValue == Constants.MAP_SEMESTER_KEY.get(Constants.SUMMER))
		yearValue = Integer.parseInt(year2.value);
	else
		yearValue = Integer.parseInt(year1.value);
	
	HashMap universityScholar;
	if (_user_type.equals(Constants.REGISTRAR))
		universityScholar = new UniversityScholarsSource(semesterValue, yearValue).getHonoraryStudents().getHonorList();
	else if (_user_type.equals(Constants.COLLEGE)){
		College college = new CollegeSource(_office).getCollege();
		universityScholar = new UniversityScholarsSource(college, semesterValue, yearValue).getHonoraryStudents().getHonorList();
	}
	Iterator iter = universityScholar.keySet().iterator();
	String[][] listModel = new String[universityScholar.size()][7];
	int i=0;
	while(iter.hasNext()){
		Student student = iter.next();
		listModel[i][0] = (i + 1) + "";
		listModel[i][1] = student.getStudentNumber();
		listModel[i][2] = student.getLastName() + " " + student.getFirstName() + " " + student.getMiddleName();
		listModel[i][3] = student.getSex();
		listModel[i][4] = student.getCurriculum().getDegreeProgram().getCollege().getCollegeCode();
		listModel[i][5] = student.getCurriculum().getDegreeProgram().getDegreeCode();
		listModel[i][6] = universityScholar.get(student).toString();
		i++;
	}
	ListModel strset = new SimpleListModel(listModel);
	contents_win.getFellow("honorary_g").setModel(strset);
	contents_win.getFellow("honorary_g").setRowRenderer(new HonoraryStudentsRenderer());
}


showHonoraryList(){
	try{
	if(type.getSelectedItem().getLabel().equals(_honor_roll)){
		retrieveHonorRollList();
	}
	else if(type.getSelectedItem().getLabel().equals(_college_scholar)){
		retrieveCollegeScholarList();
	}
	else if(type.getSelectedItem().getLabel().equals(_university_scholar)){
		retrieveUniversityScholarList();
	}
	}catch(Exception e){alert("Check information supplied");}
}



/* [start]	automatically updates the 'to' value of academic year based on the
			current 'from' value of the academic year */
private void updateAY(){
	try{
		year2.value = (Integer.parseInt(event.value) + 1).toString();
	}catch(Exception e) {year1.value = null; year2.value = null;}
}
/* [end] */